<!DOCTYPE html>
<html lang="en">

<head>
    <title>列表的数据展示</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="./js/vue2.js"></script>
    <link rel="stylesheet" href="./css/animate.css">
    <link rel="stylesheet" href="./css/弹框 .css">
    <style>
        #app {
            width: 600px;
            margin: 10px auto;
        }

        .tb {
            border-collapse: collapse;
            width: 100%;
        }

        .tb th {
            background-color: #0094ff;
            color: white;
        }

        .tb td,
        .tb th {
            padding: 5px;
            border: 1px solid black;
            text-align: center;
        }

        .add {
            padding: 5px;
            border: 1px solid black;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>

    <body>
        <div id="app">
            <div class="add">
                编号:<input type="text" v-model="addData.id">
                品牌名称:<input type="text" v-model="addData.name">
                <input type="button" value="添加" @click="add">
            </div>
            <div class="add">
                品牌名称:
                <input type="text" placeholder="请输入搜索条件" v-model="searchdata">
            </div>
            <div>
                <table class="tb">
                    <tbody>
                        <tr>
                            <th>编号</th>
                            <th>品牌名称</th>
                            <th>创立时间</th>
                            <th>操作</th>
                        </tr>
                        <tr v-for="(value,index) in searchData" :key="index">
                            <td>{{value.id}}</td>
                            <td>{{value.name}}</td>
                            <td>{{value.time | mytime('/')}}</td>
                            <td>
                                <a href="#" @click="deleteData(index)">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" v-show="searchData.length ==0">你怕是个魔鬼，没有数据啦！</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <!-- 弹框 -->
            <transition name="" mode=""
            enter-active-class="animated zoomIn"
            >
                    <div id="popBox" v-show="isshow">
                            <div class="close">
                                <a href="javascript:void(0)" @click="close">关闭</a>
                            </div>
                            <input type="button" value="确定" id="anniu1" @click="sure">
                            <input type="button" value="取消" id="anniu2" @click="cancel">
                        </div>
            </transition>
            
        </div>
    </body>
</body>
<script>
    // 时间过滤器
    Vue.filter('mytime', function (time, sc) {
        var date = new Date(time);
        var year = date.getFullYear();
        /* 在日期格式中，月份是从0开始的，因此要加0
         * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
         * */
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        // 拼接
        return year + sc + month + sc + day + " " + hours + ":" + minutes + ":" + seconds;
    })
    var vm = new Vue({

        el: "#app",
        data: {
            isshow: false,
            searchdata: '',
            getID:'',
            list: [
                { id: 1, name: '秦时明月', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 2, name: '侠岚', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 3, name: '魁拔', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 4, name: '十万个冷笑话', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 5, name: '钢羽', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 6, name: '星游记', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 7, name: 'Q版三国', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 8, name: '夺宝幸运星', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 9, name: '三国演义', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' },
                { id: 10, name: '偷星九月天', time: 'Tue Jun 25 2019 11:28:30 GMT+0800 (中国标准时间)' }
            ],
            addData: { id: '', name: '', time: Date() }
        },
        methods: {
            deleteData(id) {
                this.isshow=true;
                this.getID=id;
                
            },
            add() {
                this.list.push(this.addData);
            },
            sure(id){
                this.list.splice(this.getID)
                this.isshow=false;
            },
            cancel(){
                this.isshow=false;
            },
            close(){
                this.isshow=false;
            }

        },
        computed: {
            searchData() {
                return this.list.filter(e => e.name.indexOf(this.searchdata) != -1);
            }
        }
    })
</script>

</html>